package com.atguigu.tingshu.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * projectName: com.atguigu.tingshu.search.config
 *
 * @author: 杨天伦
 * description:
 * time: 2025/6/28 22:52
 */
@Component
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {

        //获取cpu线程数
        int cpuNum = Runtime.getRuntime().availableProcessors();
        //自定义线程池
        return new ThreadPoolExecutor(cpuNum,
                8,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()

        );
    }

}
